<?php

    if (!defined('EXPONENT')) exit('');

    $link = null;
    $config=null;
    if (isset($_GET['id'])) {
        $link = $db->selectObject('abbanner','id='.intval($_GET['id']));
        $config=null;
        if ($link) {
            $loc = unserialize($link->location_data);
            $config = $db->selectObject('abbannermodule_config',"location_data='".serialize($loc)."'");
        }
    }
    else
    {
        $config = $db->selectObject('abbannermodule_config',"location_data='".serialize($loc)."'");
    }
    if ($config == null) {
        $template = new template('abbannermodule','notconfigured',$loc);
        $template->output();
    }

    if (($link && exponent_permissions_check('edit',$loc)) || (!$link && exponent_permissions_check('create',$loc))  || exponent_permissions_check('administrate',$loc)
    ) {
        if (!isset($link->id))
            $type=intval($_REQUEST['type']);
        else
            $type = $link->show_type;
        $form = abbanner::form($link,$config, $type);
        $form->location($loc);
        $form->meta('action','save');
        $form->meta('type',$type);

        $template = new template('abbannermodule','_form_edit');
        $template->assign('is_edit',(isset($link->id)? 1 : 0));
        $template->assign('form_html',$form->toHTML());
        $template->output();
        
        exponent_sessions_set("AB_THEME_TOP_CONTAINER_SRC","top_loginmodule_".LANG);
    exponent_sessions_set("AB_THEME_TOP_CONTAINER_TYPE","textmodule");
    } else {
        exponent_http_error(404);
    }

?>